package com.longge;

public class LongestSubarray {


    public int longestSubarray(int[] nums) {
        int left = 0, right = 0,zero = 0,max = 0;
        while (right < nums.length) {
            // 增⼤窗⼝
            if (nums[right]==1){
                right++;
            }else if (nums[right]==0){
                zero++;
                right++;
            }
            // 缩小窗口
            while (zero>1) {
                if (nums[left]==1){
                    left++;
                }else if (nums[left]==0){
                    zero--;
                }
                left++;
            }
            max = Math.max(max,right-left);
        }
        return max;

    }
}
